/***************************************************************************
 创建者：华磊
 开始时间：         : 2020.12.19
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   坐标系指令属性编辑视窗
*                                                                         *
 ***************************************************************************/
#include "coordinateinstructionview.h"
#include "ui_coordinateinstructionview.h"
#include "../../programView/programview.h"


CoordinateInstructionView::CoordinateInstructionView(int styleId,QWidget *parent):
    QWidget(parent),
    ui(new Ui::CoordinateInstructionView)
{
    ui->setupUi(this);
    initialDisplayStyle(styleId);

    //点位数值限制
    ui->UTOOL_Index_lineEdit->setValidator(new QIntValidator(1, 10, this));
    ui->UTOOL_lineEdit->setValidator(new QIntValidator(1, 100, this));
    ui->UFRAME_Index_lineEdit->setValidator(new QIntValidator(1, 9, this));
    ui->UFRAME_lineEdit->setValidator(new QIntValidator(1, 100, this));
}

void CoordinateInstructionView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->note_GBox->hide();
        ui->forward_Btn->setGeometry(10,350,70,40);
        ui->save_Btn->setGeometry(360,350,70,40);
        break;
    default:
        break;
    }
}

void CoordinateInstructionView::updateView()
{
    if(EM_COORDINATE_SETTING_TOOL == selectType)
    {
        ui->UTOOL_radioButton->setChecked(true);
        ui->UTOOL_Index_lineEdit->setText(QString::number(setToolIndex));
        ui->UTOOL_lineEdit->setText(QString::number(toolPRValue));
    }
    else
    {
        ui->UTOOL_radioButton->setChecked(false);
        ui->UTOOL_lineEdit->clear();
    }

    if(EM_COORDINATE_SETTING_FRAME == selectType)
    {
        ui->UFRAME_radioButton->setChecked(true);
        ui->UFRAME_Index_lineEdit->setText(QString::number(setFrameIndex));
        ui->UFRAME_lineEdit->setText(QString::number(framePRValue));
    }
    else
    {
        ui->UFRAME_radioButton->setChecked(false);
        ui->UFRAME_lineEdit->clear();
    }

    if(EM_COORDINATE_SETTING_TOOL_NUM == selectType)
    {
        ui->UTOOL_NUM_radioButton->setChecked(true);
        ui->UTOOL_NUM_lineEdit->setText(selectToolValue);
    }
    else
    {
        ui->UTOOL_NUM_radioButton->setChecked(false);
        ui->UTOOL_NUM_lineEdit->clear();
    }

    if(EM_COORDINATE_SETTING_FRAME_NUM == selectType)
    {
        ui->UFRAME_NUM_radioButton->setChecked(true);
        ui->UFRAME_NUM_lineEdit->setText(selectFrameValue);
    }
    else
    {
        ui->UFRAME_NUM_radioButton->setChecked(false);
        ui->UFRAME_NUM_lineEdit->clear();
    }

    ui->note_lineEdit->setText(note);
}

void CoordinateInstructionView::getInput()
{
    setToolIndex = ui->UTOOL_Index_lineEdit->text().toInt();
    toolPRValue = ui->UTOOL_lineEdit->text().toInt();
    setFrameIndex = ui->UFRAME_Index_lineEdit->text().toInt();
    framePRValue = ui->UFRAME_lineEdit->text().toInt();
    selectToolValue = ui->UTOOL_NUM_lineEdit->text();
    selectFrameValue = ui->UFRAME_NUM_lineEdit->text();

    note = ui->note_lineEdit->text();
}

void CoordinateInstructionView::on_UTOOL_radioButton_clicked()
{
    emit selectSetToolInstruction();
}

void CoordinateInstructionView::on_UFRAME_radioButton_clicked()
{
    emit selectSetFrameInstruction();
}

void CoordinateInstructionView::on_UTOOL_NUM_radioButton_clicked()
{
    emit selectToolNumInstruction();
}

void CoordinateInstructionView::on_UFRAME_NUM_radioButton_clicked()
{
    emit selectFrameNumInstruction();
}

void CoordinateInstructionView::on_clearNote_Btn_clicked()
{
    ui->note_lineEdit->clear();
    emit clearNote();
}

void CoordinateInstructionView::on_forward_Btn_clicked()
{
    this->close();
    programView->instructionListFlag = 0;
    programView->editInstructionViewShowOrHide();
}

void CoordinateInstructionView::on_save_Btn_clicked()
{
    getInput();
    emit finishEditInstruction();
    emit saveInstruction(instruction);
}

void CoordinateInstructionView::changeLanguage(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/coorViewEnglishLan.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    ui->retranslateUi(this);
}
